package com.bootcamp.servlet.refresh;

/**
 * @program: wrok-1101
 * @description: ${description}
 * @author: Keyu Li
 * @create: 2021-11-03 17:24
 **/

import com.bootcamp.servlet.bean.UserInfoWithImg;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;

@WebServlet(name = "ShowRegisterInfoServlet", value = "/ShowRegisterInfoServlet")
public class ShowRegisterInfoServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 通过 context域 获得注册信息封装后的对象
        UserInfoWithImg userInfo = (UserInfoWithImg) getServletContext().getAttribute("userInfoWithImg");
        response.setStatus(200);
        response.setContentType("text/html;charset=UTF-8");

        // 输出到响应报文中
        PrintWriter writer = response.getWriter();
        writer.println("<div>姓名： " + userInfo.getIdname() + "</div>");
        writer.println("<div>邮箱： " + userInfo.getEmail() + "</div>");
        writer.println("<div>生日： " + userInfo.getYear() + "-" + userInfo.getMonth() + "-" + userInfo.getDay() + "</div>");
        writer.println("<div>正在做： " + Arrays.toString(userInfo.getDoSomething()) + "</div>");
        String[] imgLocation = userInfo.getImgLocation();
        for (String s : imgLocation) {
            writer.println("<div>个性图片：<br><img style='width:200px;border-radius: 30px' src='" + request.getContextPath() + "/" + s + "'/></div>");
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
